﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using com.tiyma.common;
using com.tiyma.components;
using com.tiyma.model;
using com.tiyma.httpmoudle;

namespace com.tiyma.web
{
    public partial class Chapter : BasePage
    {
        long m_chapter_id = 0;
        public  int m_site_id = 0;
        public ChapterInfo m_chapter = null;
        public long m_user_id = 0;
        public string m_book_name = string.Empty;

        BookManager m_book_mgr = new BookManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!long.TryParse(Request["chapterId"], out m_chapter_id))
                m_chapter_id = 0;

            if (!int.TryParse(Request["siteId"], out m_site_id))
                m_site_id = 0;

            BindChapter();

            if (Token != null)
            {
                m_user_id = Token.UserId;
                m_book_name = m_chapter.BookName;
                
            }
        }

        /// <summary>
        /// 绑定章节信息
        /// </summary>
        private void BindChapter()
        {
            SiteInfo t_site_info = null;

           
            m_chapter = m_book_mgr.GetChapterInfo(m_chapter_id, m_site_id, out t_site_info,Consts.ChapterType.reader);

            if (m_chapter == null)
            {
                RedirectErrorPage();
            }

            CookieManager.SetCurReadBook(m_chapter);
          
           
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {

            Page.Title = string.Format("{0},{1}章节由体验码小说网更新", m_chapter.BookName, m_chapter.ChapterName);
            string metaDescription =
                string.Format("{0}小说阅读,{0}最新章节,{1},最新更新尽在体验码小说网,此章节由体验码小说网更新",
                m_chapter.BookName,
                (m_chapter.ChapterName != null && m_chapter.ChapterName != "" ? (m_chapter.ChapterName.Trim().Length >= 60 ? m_chapter.ChapterName.Trim().Substring(0, 60).Replace("\"", "'").Replace("<br>", "").Replace("＜p＞", "").Replace("<p>", "").Replace("<", "＜").Replace(">", "＞").Replace("　　", " ") + "..." : m_chapter.ChapterName.Trim().Replace("\"", "'")) : ""));

            mataKeywords.Content = m_chapter.BookName + ","  + m_chapter.ChapterName + ",全本,免费," + ",体验码小说网,此章节由体验码小说网更新";
            mataDescription.Content = metaDescription;


        }

       

    }
}
